<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>比较两个数的大小</title>
  <style>
    body {
      font-family: Arial, sans-serif;
    }

    label {
      display: block;
      margin-top: 10px;
    }

    input {
      margin-bottom: 10px;
    }
  </style>
</head>

<body>
  <h2>比较两个数的大小</h2>
  <label for="num1">请输入第一个数：</label>
  <input type="number" id="num1">
  <label for="num2">请输入第二个数：</label>
  <input type="number" id="num2">
  <button onclick="compareNumbers()">比较大小</button>
  <div id="result"></div>

  <script>
    function compareNumbers() {
      // 获取文本框中的值，并转换为浮点数
      const num1 = parseFloat(document.getElementById('num1').value);
      const num2 = parseFloat(document.getElementById('num2').value);

      // 判断输入是否为有效的数字
      if (isNaN(num1) || isNaN(num2)) {
        document.getElementById('result').innerHTML = '请输入有效的数字';
      } else {
        if (num1 > num2) {
          document.getElementById('result').innerHTML = num1 + '大于' + num2;
        } else if (num1 < num2) {
          document.getElementById('result').innerHTML = num1 + '小于' + num2;
        } else {
          document.getElementById('result').innerHTML = num1 + '等于' + num2;
        }
      }
    }
  </script>
</body>

</html>